﻿///***************************************************************
/// 시  스  템 : Updms.Fit
/// 단위시스템 : FIT
/// 계      층 : Presentation Layer
/// 프로그램명 : Fit3010p
/// 파  일  명 : Fit3010p.aspx.cs
/// 설      명 : 운동종류요약 팝업
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2014-05-23 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Web;

using SMFramework.Configuration;
using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Base.AppFramework;
using Base.AppFramework.Web.UI.CommandBar;

using Updms.Fit.Exe;
using System.Web.UI.WebControls;

namespace Updms.Fit
{
	public partial class Fit3010p : Updms.Common.BaseClass.PageBase
	{
		#region 콘트롤

		public static readonly string PID = "Fit3010p";
		Global global = new Global();

		private string training_type_id = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				OnPageLoad();
				if (CheckViewAuth())
				{
					SelectProcess();
				}
			}
		}

		//OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
		}

		#endregion

		#region CheckViewAuth

		//인증검사
		private bool CheckViewAuth()
		{
			using (AccessCheck access = new AccessCheck())
			{
				//접근권한 체크
				if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
				{
					Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					return false;
				}
				return true;
			}
		}

		#endregion

		#region SetInit

		// SetInit
		private void SetInit()
		{
			if (Request.QueryString["training_type_id"] != null)
			{
				training_type_id = Server.UrlDecode(Request.QueryString["training_type_id"].ToString().Trim());
			}
		}

		#endregion

		#region SelectProcess

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			int li_image_file_cnt = 0;

			lo_dp.AddProperty("ls_training_type_id", typeof(int), training_type_id);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			//DataTable명 지정
			string[] dt_name = new string[] {	"FIT3010P_FILE",
												"FIT3010P_SUMMARY"
											};

			using (Fit3010p_NT _Fit3010p_NT = new Fit3010p_NT())
			{
				lo_ds.Merge(_Fit3010p_NT.GetTrainingTypeSummary(lo_dp, dt_name));
			}

			//첨부파일
			string dt_name_file = dt_name[0];
			if (DataSetUtil.CheckTable(lo_ds, dt_name_file))
			{
				if (DataSetUtil.GetRowCount(lo_ds, dt_name_file) > 0)
				{
					string ls_image_urls = "";
					for (int i = 0; i < DataSetUtil.GetRowCount(lo_ds, dt_name_file); i++)
					{
						string ls_file_dir = DataSetUtil.GetFldStr(lo_ds, dt_name_file, i, "File_Dir");
						string ls_file_nm = DataSetUtil.GetFldStr(lo_ds, dt_name_file, i, "File_Nm");
						string ls_file_ext = DataSetUtil.GetFldStr(lo_ds, dt_name_file, i, "File_Ext");
						string ls_image_file = FILE_PATH_UPLOAD + "\\" + ls_file_dir + "\\" + ls_file_nm;

						//실제파일이 있는지 검사
						if (FileUtil.IsFileExist(ls_image_file))
						{
							//확장자가 이미지파일인지
							if (ValidationUtil.IsFileExtImg(ls_file_ext))
							{
								li_image_file_cnt++;
								ls_image_urls = ls_image_urls
									+ "<img src=\"" + FILE_PATH_UPLOAD_WEB_PATH + ls_file_dir + "/" + ls_file_nm + "\" border=\"0\" /><br />";
							}
						}
					}

					lbl_image_url.Text = (li_image_file_cnt > 0) ? ls_image_urls : "";
				}
			}

			//운동종류설명
			string dt_name_summary = dt_name[1];
			if (DataSetUtil.CheckTable(lo_ds, dt_name_summary))
			{
				if (DataSetUtil.GetRowCount(lo_ds, dt_name_summary) > 0)
				{
					lbl_training_part.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Training_Part_Nm");
					lbl_training_nm.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Training_Nm");
					lbl_training_muscle_major.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Training_Muscle_Major");
					lbl_training_muscle_minor.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Training_Muscle_Minor");
					txt_howto.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Howto");
					txt_precaution.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Precaution");
					txt_tip.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Tip");
					lbl_weight_calc_rate.Text = DataSetUtil.GetFldStr(lo_ds, dt_name_summary, "Weight_Calc_Rate");
				}
			}
		}

		#endregion

	}
}